package framework.drawer.swing.gui;

import java.awt.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JPanel;

import framework.view.BaseMenuGroup;

public class SideBar extends JPanel implements ISideBar {
    private List<EditorToolsPanel> menuGroups;
    private Map<ISideBarElement, String> externalContributionElements = new HashMap<ISideBarElement, String>();

    public SideBar(List<BaseMenuGroup> menuGroups) {
    	this.menuGroups = new ArrayList<EditorToolsPanel>();
    	for(BaseMenuGroup group : menuGroups) {
    		EditorToolsPanel panel = new EditorToolsPanel(group.getCaption(), group.getMenuItems(), group.getJButtons());
    		this.menuGroups.add(panel);
    	}
    	
        setupUI();
    }
    
    private void setupUI() {
        setUI(new SideBarUI(this));
    }

    public void addElement(ISideBarElement element, String title) {
        this.externalContributionElements.put(element, title);
    }
    
    public List<EditorToolsPanel> getToolsPanels() {
    	return menuGroups;
    }

    protected Map<ISideBarElement, String> getExternalContributionElements() {
        return this.externalContributionElements;
    }

    public Component getAWTComponent() {
        return this;
    }
    
}
